Estoy creando un controlador de comandos de bot de Discord y sigo recibiendo este error:
(await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => { ^ TypeError: [] is not a functionAquí está mi código:
const { Perms } = require('../Validation/Permissions'); const { Client } = require('discord.js') const { promisify } = require("util") const { glob } = require('glob'); const PG = promisify(glob) const Ascii = require('ascii-table') /** * @param {Client} client */ module.exports = async (client) => { const Table = new Ascii('Command Loaded') CommandsArray = [] (await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => { const command = require(file); if (!command.name) return Table.addRow(file.split("/")[7], 'FAILED', 'Missing a name.') if (!command.description) return Table.addRow(command.name, 'FAILED', 'Missing the description.') if (command.permission) { if (Perms.includes(command.permission)) command.defaultPermission = false; else return Table.addRow(command.name,'FAILED','Permission is invalid') } client.commands.set(command.name, command); CommandsArray.push(command); await Table.addRow(command.name, 'SUCCESSFUL'); }) console.log(Table.toString()) // Permissions check // client.on('ready', async() => { const MainGuild = await client.guilds.cache.get('940180806696058910'); MainGuild.commands.set(CommandsArray).then(async (command) => { const Roles = (commandName) => { const cmdPerms = CommandsArray.find((c) => c.name === commandName).permission if (!cmdPerms) return null; return MainGuild.roles.cache.filter((r) => r.permissions.has(cmdPerms)) } const fullPermissions = command.reduce((accumulator, r) => { const roles = Roles(r.name); if (!roles) return accumulator; const permissions = roles.reduce((a, r) => { return [...a,{id: r.id, type: 'ROLE', permission: true}] }, []) return [...accumulator, {id: r.id, permissions}] }, []) await MainGuild.commands.permissions.set({ fullPermissions }); }) }) }Busqué en Google, pero no pude encontrar nada relacionado solo con [], el error de tipo generalmente aparece cuando hay un error ortográfico en su código. He revisado mi código varias veces y no he podido encontrar ningún error, simplemente no puedo resolver esto. Realmente agradecería alguna ayuda, ¡gracias!
¡Utilice punto y coma!
Agregar ; en la línea sobre el PG donde define una matriz vacía, JS ve la matriz y también los corchetes justo después y esto piensa que está ejecutando una función porque JS cuando se compila no mira las líneas o los espacios.
CommandsArray = []; (await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => {